import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class SetWindow extends JFrame
        implements ActionListener {
    JTextField name;//姓名
    JButton button;//提交按钮
    JRadioButton radio1, radio2;
    ButtonGroup group;//性别
    JRadioButton radio3, radio4;//返校情况
    JCheckBox checkBox1, checkBox2, checkBox3, checkBox4;//健康情况
    JComboBox<String> comBox;
    JTextArea area;//显示信息

    JPanel jp1;
    JPanel jp2;
    JPanel jp3;
    JPanel jp4;
    JPanel jp5;
    JPanel jp6;
    JPanel jp7;

    public SetWindow() {
        super();
        init();
        setResizable(false);
        setVisible(true);
    }

    void init() {
        setLayout(new FlowLayout());//布局

        jp1 = new JPanel();//姓名
        jp1.add(new JLabel("姓名:"));
        name = new JTextField(10);
        jp1.add(name);

        jp2 = new JPanel();//性别
        jp2.add(new JLabel("性别:"));
        group = new ButtonGroup();
        radio1 = new JRadioButton("男");
        radio2 = new JRadioButton("女");
        group.add(radio1);
        group.add(radio2);
        jp2.add(radio1);
        jp2.add(radio2);

        jp3 = new JPanel();//返校情况
        jp3.add(new JLabel("今日是否返校:"));
        group = new ButtonGroup();
        radio1 = new JRadioButton("是");
        radio2 = new JRadioButton("否");
        group.add(radio3);
        group.add(radio4);
        jp3.add(radio3);
        jp3.add(radio4);

        jp4 = new JPanel();//今日健康情况
        jp4.add(new JLabel("今日健康情况:"));
        checkBox1 = new JCheckBox("正常");
        checkBox2 = new JCheckBox("发烧(37.2以上)");
        checkBox3 = new JCheckBox("感冒");
        checkBox4 = new JCheckBox("其他");
        jp4.add(checkBox1);
        jp4.add(checkBox2);
        jp4.add(checkBox3);

        jp5 = new JPanel();//所在地区
        jp5.add(new JLabel("所在地区"));
        comBox = new JComboBox<String>();
        comBox.addItem("江西");
        comBox.addItem("武汉");
        comBox.addItem("北京");
        comBox.addItem("其他国内城市");
        comBox.addItem("其他国外城市");
        jp5.add(comBox);

        jp6 = new JPanel();//信息框
        jp6.add(new JLabel("信息显示:"));
        area = new JTextArea(6, 25);
        jp6.add(new JScrollPane(area));

        button = new JButton("提交");
        jp7 = new JPanel();
        jp7.add(button);

        add(jp1);
        add(jp2);
        add(jp3);
        add(jp4);
        add(jp5);
        add(jp6);
        add(jp7);
        button.addActionListener(this);

    }

    @Override
    public void actionPerformed(ActionEvent arg0) {
        String s = "";
        String s1 = "今日健康状况";
        if (arg0.getSource() == button) {

            s = s + "姓名：" + name.getText() + "\n";

            if (radio1.isSelected()) {
                s = s + "性别:" + radio1.getText() + "\n";
            }
            if (radio2.isSelected()) {
                s = s + "性别:" + radio2.getText() + "\n";
            }


            if (radio1.isSelected()) {
                s = s + "今日是否从外地返校:" + radio3.getText() + "\n";
            }
            if (radio2.isSelected()) {
                s = s + "今日是否从外地返校:" + radio4.getText() + "\n";
            }


            if (checkBox1.isSelected()) {
                s1 = s1 + checkBox1.getText() + "  ";
            }
            if (checkBox2.isSelected()) {
                s1 = s1 + checkBox2.getText() + "  ";
            }
            if (checkBox3.isSelected()) {
                s1 = s1 + checkBox3.getText();
            }
            if (checkBox3.isSelected()) {
                s1 = s1 + checkBox4.getText();
            }

        }

        s = s + s1 + "\n";

        s = s + "所在地区:" + comBox.getSelectedItem().toString();
        area.setText(s);
    }
}

